<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/ssb/include/common-base.jsp"%>
  <title>保险产品详情配置</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>

<!-- Part 一、 以下是body主体内容的模块区域 -->
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

  <!-- top start -->
  <%@include file="/common/ssb/top.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/ssb/left.jsp" %>
  <!-- left end-->

  <div class="content-wrapper">
	  <style>
		  .table-min tbody tr td{
			  padding: 5px;

		  }
		  .table-min tbody tr td .form-group .form-control{
			  border-radius: 3px;
			  height: 28px;
		  }
		  .my-rg-btn button{
			  float: right !important;
			  margin:0px 5px;
		  }
		  .range_name{
			  font-size:16px;
		  }
	  </style>
    <!-- Main start -->
	<section class="content-header">
	  <h3 style="font-size:20px;">
		  ${param.proName}
		  <button class="btn btn-primary btn-sm" onclick="addProRange()"><i class="fa fa-plus-circle"></i> 新增保险方案</button>
		 &nbsp;<button class="btn btn-info btn-sm" onclick="toBack()"><i class="fa fa-reply"></i> 返回上级</button>
	  </h3>
		<div>
			<form id="searchForm_proRange" action="javascript:;" >
				<input type="hidden" name="pageName" value="ss-insur-pro-range"/>
				<input type="hidden" name="formName" value="searchForm"/>
				<input type="hidden" name="ssInsurProRange.w_proId" value="${param.proId}"/>
			</form>
		</div>
	</section>
	<section class="content">
      <div class="row">
        <div class="col-xs-12">
			<div class="row" id="proRange-body">


			</div>
        </div>
      </div>
<div win-title="保障内容窗口" class="modal fade" id="my_modal_bznr" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:60%;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					×
				</button>
				<h4 class="modal-title">
					<font color="red">[${param.proName}]-[<span id="span_bznr_range"></span>]-[<span id="span_bznr_limit"></span>]-保障内容配置</font> 
				</h4>
			</div>
			<div class="modal-body">
				<div class="nav-tabs-custom">
					<ul class="nav nav-tabs" id="myTab-edit">
					</ul>

					<!-- tab content start -->
					<div class="tab-content ">
						<div class="tab-pane active" id="tabEdit_1">
							<form class="form-horizontal addFormBody" role="form" id="detailForm2" action="javascript:void(0)">
								<div id="detailForm1_hidden" style="display:none;">
									<input type="hidden" name="pageName" value="ss-insur-pro-detail-addbatch"/>
									<input type="hidden" name="formName" value="addFormBatch"/>
									<input type="hidden" name="ssInsurProDetail.w_limitId" class="tab_ssInsurProDetail_limitId"/>
									<input type="hidden" name="ifBatch" value="T"/>
									<input type="hidden" name="ssInsurProDetail.splitAttr" value="proId"/>
								</div>

								<div id="detailForm1_content">
									<table class="table table-bordered bordercolor">
										<thead>
										<tr>
											<th colspan="3">
												<button class="btn btn-info btn-sm" onclick="addDetail('detail-body1')"><i class="fa fa-plus-circle"></i> 增加保障内容</button>
											</th>
										</tr>
										<tr class="bg-info">
											<th class="w350">保障内容标题</th>
											<th class="w120">保障内容额度</th>
											<th class="hidden">保障内容概述</th>
											<th class="w80 text-center">删除</th>
										</tr>
										</thead>
										<tbody id="detail-body1">
										</tbody>
									</table>
								</div>
								<!-- temp="detailForm2_content" end -->


								<div class="form-group">
									<div class="col-sm-12">
										<div class="box-footer text-center">
											<button class="btn btn-success pull-left" type="button" onclick="mytools.closeModal('my_modal_bznr');"> 取消</button>
											<button class="btn btn-danger pull-right" type="button" onclick="submitForm1('detailForm2','my_modal_bznr');" > 提交保存</button>
										</div>
									</div>
								</div>

							</form>
						</div>

					</div>
					<!-- tab content e -->
				</div>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
</div>

		<!-- Part 二、以下是template模板定义的模块区域 -->
<script type="text/template" id="proRange-template">
		<? for ( var i = 0; i < rows.length; i++) {?>
		<div class="col-lg-12">
			<div class="panel panel-info">
				<div class="panel-heading" range-box="<?=rows[i].ssInsurProRange.rangeId?>">
					<div class="row">
						<div class="col-lg-6">
							<h3 class="range_name range_show"><?=rows[i].ssInsurProRange.rangeName?>-[<?=rows[i].ssInsurProRange.rangeCode?>]</h3>
							<div class="range_input hidden">
								<div class="col-lg-6">
									<input id="input_rangeName_<?=rows[i].ssInsurProRange.rangeId?>" name="rangeName" value="<?=rows[i].ssInsurProRange.rangeName?>" class="form-control clean" maxlength="10" placeholder="方案名称"/>
								</div>
								<div class="col-lg-6">
									<input id="input_rangeCode_<?=rows[i].ssInsurProRange.rangeId?>" name="rangeCode" value="<?=rows[i].ssInsurProRange.rangeCode?>" class="form-control clean" maxlength="10" placeholder="方案代码"/>
								</div>
							</div>
						</div>
						<div class="col-lg-6 my-rg-btn">
							<button class="btn btn-default btn-xs" onclick="delRangeInfo('<?=rows[i].ssInsurProRange.rangeId?>')"><i class="fa fa-close"></i> 删除</button>
							<button class="btn btn-default btn-xs" onclick="getProLimitList('<?=rows[i].ssInsurProRange.rangeId?>')"><i class="fa fa-refresh"></i> 刷新</button>
							<button class="btn btn-primary btn-xs" onclick="addProLimit('<?=rows[i].ssInsurProRange.rangeId?>')"><i class="fa fa-plus-circle"></i> 添加保险期限子级</button>
							<button class="btn btn-default btn-xs range_show" onclick="editRangeInfo('<?=rows[i].ssInsurProRange.rangeId?>')"><i class="fa fa-edit"></i> 编辑方案名称</button>
							<button class="btn btn-danger btn-xs range_input hidden" onclick="saveRangeInfo('<?=rows[i].ssInsurProRange.rangeId?>')"><i class="fa fa-save"></i> 保存方案名称</button>
						</div>
					</div>
				</div>
				<div class="panel-body" id="proLimit-body-<?=rows[i].ssInsurProRange.rangeId?>">

				</div>
			</div>
		</div>
   <?}?>  		
</script>
<script type="text/template" id="proLimit-template">
	<? for ( var i = 0; i < rows.length; i++) {?>
	<div class="col-lg-4" limit-box="<?=rows[i].ssInsurProLimit.limitId?>">
		<div class="box box-primary box-solid">
			<div class="box-header">
				<h5>
					<span class="badge bg-blue"><?=(i+1)?></span>
					<i class="pull-right fa fa-trash-o white fcur" onclick="delLimitInfo('<?=rows[i].ssInsurProLimit.rangeId?>','<?=rows[i].ssInsurProLimit.limitId?>')" title="删除此期限"></i>
				</h5>
			</div>
			<div class="box-body">
				<form id="form_limit_<?=rows[i].ssInsurProLimit.limitId?>" action="javascript:;">
					<input name="pageName" type="hidden" value="ss-insur-pro-limit"/>
					<input name="formName" type="hidden" value="editForm"/>
					<input name="ssInsurProLimit.w_limitId" type="hidden" value="<?=rows[i].ssInsurProLimit.limitId?>"/>
					<table class="table table-bordered table-min">
						<tbody>
						<tr>
							<td>期限名称</td>
							<td>
								<div class="form-group">
									<input name="ssInsurProLimit.limitName" id="ssInsurProLimit_limitName_<?=rows[i].ssInsurProLimit.limitId?>" value="<?=rows[i].ssInsurProLimit.limitName?>"  class="form-control clean" maxlength="30" placeholder="请输入内容"/>
								</div>
							</td>
						</tr>
						<tr>
							<td>期限单位</td>
							<td>
								<div class="form-group">
									<input type="radio" value="D" name="ssInsurProLimit.limitUnit" <?if('D'==rows[i].ssInsurProLimit.limitUnit){?> checked="checked"<?}?> /> 日&nbsp;
									<input type="radio" value="M" name="ssInsurProLimit.limitUnit" <?if('M'==rows[i].ssInsurProLimit.limitUnit){?> checked="checked"<?}?> /> 月&nbsp;
									<input type="radio" value="Y" name="ssInsurProLimit.limitUnit" <?if('Y'==rows[i].ssInsurProLimit.limitUnit){?> checked="checked"<?}?> /> 年
								</div>
							</td>
						</tr>
						<tr>
							<td>保费(元)</td>
							<td>
								<div class="form-group">
									<input name="ssInsurProLimit.premium" id="ssInsurProLimit_premium_<?=rows[i].ssInsurProLimit.limitId?>"
										   onblur="checkNumber(this)" value="<?=rows[i].ssInsurProLimit.premium?>" class="form-control clean"
										   maxlength="10" placeholder="请输入内容"/>
								</div>
							</td>
						</tr>
						<tr>
							<td>保额(元)</td>
							<td>
								<div class="form-group">
									<input name="ssInsurProLimit.amount" id="ssInsurProLimit_amount_<?=rows[i].ssInsurProLimit.limitId?>"
										   onblur="checkNumber(this)"  value="<?=rows[i].ssInsurProLimit.amount?>" class="form-control clean"
										   maxlength="10" placeholder="请输入内容"/>
								</div>
							</td>
						</tr>
						</tbody>
						<tfoot>
							<tr>
								<td colspan="2" class="text-center">
									<div class="col-lg-12">
										<div class="col-lg-6">
											<button class="btn btn-primary btn-xs" onclick="saveLimitInfo(this,'<?=rows[i].ssInsurProLimit.limitId?>')"><i class="fa fa-save"></i> 提交保存</button>
										</div>
										<div class="col-lg-6">
											<button class="btn btn-info btn-xs" style="margin-left:20px;" onclick="toAdd(this,'<?=rows[i].ssInsurProLimit.rangeId?>','<?=rows[i].ssInsurProLimit.limitId?>')"><i class="fa fa-plus-circle"></i> 保障内容配置</button>
										</div>
									</div>
								</td>
							</tr>
						</tfoot>
					</table>
				</form>
			</div>
		</div>
	</div>
	<?}?>
</script>
<script type="text/template" id="detailSave-template">
	<? for ( var i = 0; i < rows.length; i++) {?>
	<tr>
		<td style="vertical-align: middle">
			<input type="hidden" class="w220" name="ssInsurProDetail.proId" value="<?=rows[i].ssInsurProDetail.proId?>"/>
			<input type="hidden" class="w220" name="ssInsurProDetail.rangeId" value="<?=rows[i].ssInsurProDetail.rangeId?>"/>
			<input type="hidden" class="w220" name="ssInsurProDetail.limitId" value="<?=rows[i].ssInsurProDetail.limitId?>"/>
			<input type="hidden" class="w220" name="ssInsurProDetail.detailType" value="CPBZ"/>
			<input name="ssInsurProDetail.title" class="form-control" value="<?=rows[i].ssInsurProDetail.title?>"/>
		</td>
		<td style="vertical-align: middle">
			<input name="ssInsurProDetail.quota" class="form-control" maxlength="60" value="<?=rows[i].ssInsurProDetail.quota?>"/>
		</td>
		<td class="hidden">
			<textarea class="form-control" rows="1" maxlength="1000" name="ssInsurProDetail.content"><?=rows[i].ssInsurProDetail.content?></textarea>
		</td>
		<td style="vertical-align: middle;text-align:center"><i class="fa fa-trash-o" onclick="delDetailInfo(this,'<?=rows[i].ssInsurProDetail.infoId?>')"></i></td>
	</tr>
	<?}?>
</script>

<script type="text/template" id="detailView-template">
	<? for ( var i = 0; i < rows.length; i++) {?>
	<tr>
		<td style="vertical-align: middle"><?=rows[i].ssInsurProDetail.title?></td>
		<td style="vertical-align: middle"><?=rows[i].ssInsurProDetail.quota?></td>
		<td><?=rows[i].ssInsurProDetail.content?></td>
	</tr>
	<?}?>
</script>
<!-- Part 三、 以下是js模块区域 -->
<script>
var clickMenu = "pro-list";
var myPage,dataListId,searchFormId,editProCode,editRiskCname;
myPage = 10;//定义列表数据
dataListId = "proRange";//显示列表数据div的id
searchFormId = "searchForm_proRange";//范围查询表单Id
var this_proId = '${param.proId}',this_rangeId='',this_limitId='';

/**
 * 初始化数据字典，id传入#id 返回值Map用法：dictListMap["userType"][rows[i].userType]
 */
var dictListMap = DictUtil.initDictAndDymic();
$(function () {
	//1、加载分页列表数据
	getProRangeList();
	
	//2、控制是否启用token
	//setToken();


 });
function toBack() {
	window.location.href=page_admin+"/pro/pro-list";
}
//注入日历框样式
var dateObject = $('.datepicker').datepicker( {
	language : 'zh-CN',
	//inline: true,
	todayBtn : "linked",
	format : "yyyy-mm-dd",
	autoclose: true
}).on('hide',function(e) {
	//bootstrap datepicker与bootstrapValidator同时使用时选择日期后无法正常触发校验的解决方法
	//当日期选择框关闭时，执行刷新校验。
	var fieldName = $(this).attr("name");//获取当前元素name
	var formId = $(this).parents("form").eq(0).attr("id");//获取当前元素所在父层级中的就近的formId
    $("#"+formId).data('bootstrapValidator').updateStatus(fieldName,'NOT_VALIDATED',null).validateField(fieldName);
});

//给模态窗口内form表单内的所有支持必填项的元素注入校验
$(".modal").on('shown.bs.modal', function () {
	$(this).find("form").each(function(){
		var formId = $(this).attr("id");
		// console.log('shown.bs.modal.formId',formId);
		if(!strUtil.isNull(formId)){
			var formId="#"+formId;
		 	setValidate(formId);//定义add表单验证属性
			mytools.cleanValidate(formId);//清空上次校验规则提示
		}
	});
});

//范围-查询数据
function getProRangeList(){
	var index_load = layer.load(1, {shade: false});
	$.ajax({
		type:'get',
		url:common_list_url,
		data:$("#"+searchFormId).serialize(),
		dataType:'json',
		success: function(myData){
			console.log('getProRangeList.res',myData);
			if("T"==myData.flag){
				var data = baidu.template(dataListId+"-template",eval(myData));
				$("#"+dataListId+"-body").html(data);
				$("div[range-box]").each(function (i) {
					var rangeId = $(this).attr("range-box");
					getProLimitList(rangeId);
				});
			}
			layer.close(index_load);
		}
	});
}
//范围-添加
function addProRange(){
	var childCount = $("#proRange-body").find("div[range-box]").length;
	var seqNo = (childCount+1);
	var testName = "方案名称"+seqNo;
	var index_load = layer.load(1, {shade: false});
	var rangeCode="000000"+seqNo;
	var paramData = {};
	paramData['pageName']='ss-insur-pro-range';
	paramData['formName']='addForm';
	paramData['ssInsurProRange.proId']=this_proId;
	paramData['ssInsurProRange.rangeCode']=rangeCode;
	paramData['ssInsurProRange.rangeName']=testName;
	$.ajax({
		type:"post",
		url:common_submit_url,
		data:paramData,dataType:"json",
		success: function(myData){
			layer.close(index_load);
			console.log('addProRange.res',myData);
			if("T"==myData.flag) {
				getProRangeList();
			}
		}
	});
}
//方案名称-控制文本框是否显示
function editRangeInfo(rangeId){
	var rangeBox = $("#"+dataListId+"-body").find("[range-box='"+rangeId+"']");
	rangeBox.find(".range_input").removeClass("hidden");
	rangeBox.find(".range_show").addClass("hidden");
}
//范围-保存
function saveRangeInfo(rangeId){
	var rangeBox = $("#"+dataListId+"-body").find("[range-box='"+rangeId+"']");
	var rangeNameVal = rangeBox.find("input[name='rangeName']").val();
	var rangeCodeVal = rangeBox.find("input[name='rangeCode']").val();
	var index_load = layer.load(1, {shade: false});
	var paramData = {};
	paramData['pageName']='ss-insur-pro-range';
	paramData['formName']='editForm';
	paramData['ssInsurProRange.w_rangeId']=rangeId;
	paramData['ssInsurProRange.rangeName']=rangeNameVal;
	paramData['ssInsurProRange.rangeCode']=rangeCodeVal;
	$.ajax({
		type:"post",
		url:common_submit_url,
		data:paramData,dataType:"json",
		success: function(myData){
			layer.close(index_load);
			console.log('eidtProRange.res',myData);
			if("T"==myData.flag) {
				rangeBox.find(".range_name").text(rangeNameVal+"["+rangeCodeVal+"]");
				rangeBox.find(".range_input").addClass("hidden");
				rangeBox.find(".range_show").removeClass("hidden");
			}
		}
	});
}
//范围-删除
function delRangeInfo(rangeId){
	var childCount = $("#proLimit-body-"+rangeId).find("div[limit-box]").length;
	console.log('delRangeInfo.childCount',childCount);
	if(childCount>0){
		layer.alert("请先删除保险期限子级");
		return;
	}
	var index_submit = layer.confirm("您确定要删除此范围信息吗？", {btn: ["Yes","No"],closeBtn: 0,offset: "220px"}
	, function(){
		layer.close(index_submit);
		var index_load = layer.load(1, {shade: false});
		var paramData = {};
		paramData['pageName']='ss-insur-pro-range';
		paramData['formName']='delForm';
		paramData['ssInsurProRange.w_rangeId']=rangeId;
		$.ajax({
			type:"post",
			url:common_submit_url,
			data:paramData,dataType:"json",
			success: function(myData){
				layer.close(index_load);
				console.log('delProRange.res',myData);
				if("T"==myData.flag) {
					getProRangeList();
				}
			}
		});
	});
}
//期限-查询
function getProLimitList(rangeId){
	var index_load = layer.load(1, {shade: false});
	var paramData = {};
	paramData['pageName']='ss-insur-pro-limit';
	paramData['formName']='searchForm';
	paramData['ssInsurProLimit.w_rangeId']=rangeId;
	$.ajax({
		type:'get',
		url:common_list_url,
		data:paramData,
		dataType:'json',
		success: function(myData){
			console.log('getProLimitListByRangeId['+rangeId+'].res',myData);
			if("T"==myData.flag){
				var htmls = "";
				if(myData.total>0){
					htmls= baidu.template("proLimit-template",eval(myData));
				}else{
					htmls="<div class='fx8'>暂无内容，请添加！</div>";
				}
				$("#proLimit-body-"+rangeId).html(htmls);
			}
			layer.close(index_load);
		}
	});
}
//期限-添加
function addProLimit(rangeId){
	var childCount = $("#proLimit-body-"+rangeId).find("div[limit-box]").length;
	var testName = (childCount+1)+"年";
	var limitCode="No_"+new Date().getTime();
	var index_load = layer.load(1, {shade: false});
	var paramData = {};
	paramData['pageName']='ss-insur-pro-limit';
	paramData['formName']='addForm';
	paramData['ssInsurProLimit.proId']=this_proId;
	paramData['ssInsurProLimit.rangeId']=rangeId;
	paramData['ssInsurProLimit.limitCode']=limitCode;
	// paramData['ssInsurProLimit.premium']='';
	// paramData['ssInsurProLimit.amount']='';
	paramData['ssInsurProLimit.limitUnit']='Y';
	paramData['ssInsurProLimit.limitName']=testName;
	$.ajax({
		type:"post",
		url:common_submit_url,
		data:paramData,dataType:"json",
		success: function(myData){
			layer.close(index_load);
			console.log('addProLimit.res',myData);
			if("T"==myData.flag) {
				getProLimitList(rangeId);
			}
		}
	});
}
//期限-删除
function delLimitInfo(rangeId,limitId) {
	var index_load = layer.load(1, {shade: false});
	$.ajax({
		type:"get",
		url:common_list_url,
		data: {'pageName':'ss-insur-pro-detail','formName':'searchForm','ssInsurProDetail.w_limitId':limitId},
		dataType:"json",
		success: function(myData){
			layer.close(index_load);
			console.log('pro-detail.res',myData);
			if(myData.total>0) {
				layer.alert("请先删除配置的保障内容");
				return;
			}else{
				var index_submit = layer.confirm("您确定要删除此期限信息吗？", {btn: ["Yes","No"],closeBtn: 0,offset: "220px"}
				, function(){
					layer.close(index_submit);
					var index_load = layer.load(1, {shade: false});
					var paramData = {};
					paramData['pageName']='ss-insur-pro-limit';
					paramData['formName']='delForm';
					paramData['ssInsurProLimit.w_limitId']=limitId;
					$.ajax({
						type:"post",
						url:common_submit_url,
						data:paramData,dataType:"json",
						success: function(myData){
							layer.close(index_load);
							console.log('delLimitInfo.res',myData);
							if("T"==myData.flag) {
								getProLimitList(rangeId);
							}
						}
					});
				});
			}
		}
	});

}
//验证文本框必须是数字
function checkNumber(obj) {
	var objVal = $(obj).val();
	if(!strUtil.isNull(objVal)){
		var objId = $(obj).attr("id");
		if(isNaN(objVal)){
			layer.tips('只能输入数字！', '#'+objId, {tips: 3});
			$(obj).val("");
			return;
		}
	}
}
//期限-保存
function saveLimitInfo(obj,limitId){
	var formLimitObj = $("#form_limit_"+limitId);
	var limitNameObj=formLimitObj.find("input[name='ssInsurProLimit.limitName']");
	if(strUtil.isNull(limitNameObj.val())){
		layer.tips('此项不能为空！', '#'+$(limitNameObj).attr("id"), {tips: 3});
		$(limitNameObj).val("");
		return;
	}
	var premiumObj=formLimitObj.find("input[name='ssInsurProLimit.premium']");
	if(strUtil.isNull(premiumObj.val())){
		layer.tips('此项不能为空！', '#'+$(premiumObj).attr("id"), {tips: 3});
		$(premiumObj).val("");
		return;
	}
	var amountObj=formLimitObj.find("input[name='ssInsurProLimit.amount']");
	if(strUtil.isNull(amountObj.val())){
		layer.tips('此项不能为空！', '#'+$(amountObj).attr("id"), {tips: 3});
		$(amountObj).val("");
		return;
	}
	var index_load = layer.load(1, {shade: false});
	$.ajax({
		type:"post",
		url:common_submit_url,
		data:formLimitObj.serialize(),
		dataType:"json",
		success: function(myData){
			layer.close(index_load);
			console.log('saveLimitInfo.res',myData);
			if("T"==myData.flag) {
				layer.msg("保存成功！");
			}
		}
	});
}
//保障内容-modal
function toAdd(obj,rangeId,limitId){
	mytools.cleanData(".addFormBody");//清空表单元素上次填写的内容；
	this_rangeId=rangeId;
	this_limitId=limitId;
	var formLimitObj = $("#form_limit_"+limitId);
	var rangeNameVal = $("#input_rangeName_"+rangeId).val();
	var limitNameVal = formLimitObj.find("input[name='ssInsurProLimit.limitName']").val();
	$("#span_bznr_range").text(rangeNameVal);
	$("#span_bznr_limit").text(limitNameVal);
	$(".tab_ssInsurProDetail_limitId").val(limitId);
	getProDetailList(this_limitId,'detail-body1','detailSave');

	$("#my_modal_bznr").modal("show");
}

//添加一行保障明细文本框
function addDetail(bodyId) {
	var myData_detail = {rows:[{'ssInsurProDetail':{'title':'','proId':this_proId,'rangeId':this_rangeId,'limitId':this_limitId,'quota':'','content':'无'}}]};
	console.log('myData_detail',myData_detail);
	var data_detail = baidu.template("detailSave-template",eval(myData_detail));
	$("#"+bodyId).append(data_detail);
}
//保障明细查询
function getProDetailList(limitId,bodyId,temp) {
	var index_load = layer.load(1, {shade: false});
	$("#"+bodyId).html('');
	$.ajax({
		type:"get",
		url:common_list_url,
		data: {'pageName':'ss-insur-pro-detail','formName':'searchForm','ssInsurProDetail.w_limitId':limitId},dataType:"json",
		success: function(myData){
			layer.close(index_load);
			console.log('pro-detail.res',myData);
			if("T"==myData.flag) {
				var data = baidu.template(temp+"-template", eval(myData));
				$("#"+bodyId).html(data);
			}
		}
	});
}
//保障内容-删除
function delDetailInfo(obj,detailId) {
	if(!strUtil.isNull(detailId)){
		var index_load = layer.load(1, {shade: false});
		var paramData = {};
		paramData['pageName']='ss-insur-pro-detail';
		paramData['formName']='delForm';
		paramData['ssInsurProDetail.w_infoId']=detailId;
		$.ajax({
			type:"post",
			url:common_submit_url,
			data:paramData,dataType:"json",
			success: function(myData){
				layer.close(index_load);
				console.log('delDetailInfo.res',myData);
				if("T"==myData.flag) {
					$(obj).parent().parent().remove();
				}
			}
		});
	}else{
		$(obj).parent().parent().remove();
	}
}
//提交tab1表单数据
function submitForm1(formId,tabId){
	var dataCount  = $("#detail-body1").find("tr").length;
	if(dataCount==0){
		layer.alert("请先增加数据！");
		return;
	}
	//校验规则-表单提交时触发
	// var validate = $('#'+formId).data('bootstrapValidator').validate();
	// if(!validate.isValid()){ //如果校验不通过就返回
	//     return;
	// }
	var index_submit = layer.confirm('您确定要保存信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		var result = submitForm(formId,tabId);
		if(result){
			layer.msg("保障内容保存成功！", {closeBtn: 0 });
			mytools.closeModal(tabId);
	  	}
	});
	
 }
//提交表单数据
function submitForm(formId,tabId){
	var result;
	var index_load = layer.load(1, {shade: false});
	$.ajax({
	    type:'post',
	    url:common_submit_url,
	    data:$("#"+formId).serialize(),
	    async:false,
	    dataType:'json',
	    success: function(myData){ 
	     console.log(myData);
	        if(myData.flag=="T"){
	        	result = myData;
	    	}else{
	    		setToken();
	     		layer.alert(myData.msg);
	    	}
	        layer.close(index_load);
	  	},
	     error: function (e) {
		     layer.close(index_load);
     	} 
	});	
	return result;
}
//设置token
function setToken(){
	$.ajax({
	    type:'get',
	    url:'${ctx}/sendPage/token?token=true',
	    dataType:'text',
	    success: function(myData){
	    	console.log(myData);
			$('.formToken').val(myData);
	  	}
	});	
}

/**** Part 四、以下是自定义新增方法  ****/
//1.定义校验规则-定义
function setValidate(id){
	$(id).each(function(){
		$(this).bootstrapValidator({
		    feedbackIcons: {
		        valid: 'glyphicon glyphicon-ok',
		        invalid: 'glyphicon glyphicon-remove',
		        validating: 'glyphicon glyphicon-refresh'
		    },/** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
		 	fields:{
		 		/** 可自定义新增验证规则
		    	"uctUser.userEname":{
		    		 validators: {
		    			 regexp: {
		    				 regexp: /^[0-9]+$/,
		                      message: '只能是数字'
		                  }
		              }
		    	}
		    	**/
				}
		});
	});
}


</script>
</section>
<!-- Main end -->   
</div>
<!-- foot start -->
<%@include file="/common/ssb/foot.jsp" %>
<!-- foot start -->
</div>
<!-- /.content-wrapper -->
</body>
</html>














































